package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.SettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;

    //查询通用设置
    @GetMapping("/users/settings")
    public SettingVo findSetting() {
        return settingManager.findSetting();
    }

    //设置陌生人问题
    @PostMapping("/users/questions")
    public void saveOrUpdateQuestion(@RequestBody Map<String, String> map) {
        String content = map.get("content");

        settingManager.saveOrUpdateQuestion(content);
    }

    //设置通知
    @PostMapping("/users/notifications/setting")
    public void saveOrUpdateNotification(@RequestBody Notification notificationParam) {
        settingManager.saveOrUpdateNotification(notificationParam);
    }

    //黑名单查询
    @GetMapping("/users/blacklist")
    public PageBeanVo findBlackList(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {
        return settingManager.findBlackList(pageNum, pageSize);
    }


    //移除黑名单用户
    @DeleteMapping("/users/blacklist/{uid}")
    public void deleteBlackUser(@PathVariable("uid") Long blackUserId) {
        settingManager.deleteBlackUser(blackUserId);
    }
}
